package com.dangf.hzapp;

import com.dangf.hzapp.entity.User;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/**
 * APP 配置
 * @author 韦海生
 * @date 2014年7月31日
 */
public class Config {
	public static final String HOST_URL = "http://hezuapp.jd-app.com/hais";		//服务器地址
	public static final String APP_ID = "com.dangf.hzapp";			//应用唯一标示
	
	
	/**
	 * 获取缓存中的 User
	 * @param context
	 * @return
	 */
	public static User getCacheToken(Context context) {
		 SharedPreferences s = context.getSharedPreferences(Config.APP_ID, Context.MODE_PRIVATE);
		 User u = new User();
		 u.setId(s.getLong("user.Id", 0));
		 u.setUsername(s.getString("user.Username", ""));
		 u.setPassword(s.getString("user.Password", ""));
		 u.setEmail(s.getString("user.Email", ""));
		 u.setName(s.getString("user.Name", ""));
		 u.setPhoto(s.getString("user.Photo", ""));
		 u.setToken(s.getString("user.Token", ""));
		return u;
	}

	
	/**
	 * 缓存User
	 * @param context
	 * @param User
	 */
	public static void cacheUser(Context context, User user) {
		Editor e = context.getSharedPreferences(Config.APP_ID,Context.MODE_PRIVATE).edit();
		e.putLong("user.Id", user.getId());
		e.putString("user.Username", user.getUsername());
		e.putString("user.Password", user.getPassword());
		e.putString("user.Email", user.getEmail());
		e.putString("user.Name", user.getName());
		e.putString("user.Photo", user.getPhoto());
		e.putString("user.Token", user.getToken());
		e.commit();
	}
}
